<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
    function _init() {
        $data = array();
        $data['mainMenu'] = makeMainMenu();

        $data['email']             = null;
        $data['errorMessage']      = null;
        $data['errorMessageClass'] = 'hide';
        return $data;
    }

	public function index($text=null)
	{
        $data = Login::_init();
        $data['content'] = $text;
		$this->load->view('login',$data);
	}

    public function tryLogin() {
        $this->load->model('admin','',TRUE);
        $email    = $this->input->post('email', TRUE);
        $password = $this->input->post('password', TRUE);

        $loginArray = $this->admin->tryLogin($email,$password);

        if ($loginArray == false) {
            $data = Login::_init();
            $data['email'] = $email;
            $data['errorMessage'] = 'Your account could not be located.';
            $data['errorMessageClass'] = '';
            $this->load->view('login',$data);
        } else {
            $sessionArray['fullName'] = $loginArray['FullName'];
            $sessionArray['email']    = $email;
            $sessionArray['logged']   = true;
            $this->session->set_userdata($sessionArray);
            header('Location: '.BASE_URL);
        }
    }

    public function logout() {
        $this->session->sess_destroy();

        $data = Login::_init();
        header('Location: '.BASE_URL);
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
